//获取应用实例
const app = getApp()
Page({
  data: {
    //列表List
    szzstArr: [],
    //总页数
    totalPage: '',
    search: ['搜索用户', '操作内容'],
    searchContent: ['点击选择操作内容', '新闻', '通讯录', '工资查询', '发行数据', 'APP下载', '最新资讯', '轮播图', '首页', '我的', '最新资讯', '工资查询', '电子物品', '信息化周报', '调研报告', '公众号统计', '反馈意见', '集团选题审批', '人民社评分', '选题追踪','AI助手'],
    //搜索时用户name   
    userName: '',
    //确定查询按钮是否显示
    searchShow: true,
    //操作内容下拉是否显示
    contentShow: false,
    //用户搜索的input框是否显示
    userInputShow: true,
    //搜索操作内容的变量
    contentName: '',
    //查询类型的下角标
    searchIndex: 0,
    //操作内容下拉框的下角标
    searchContentIndex: 0,
    //分页是数组
    page: [],
    //分页的下角标
    index: 0,
  },
  //初始化
  onLoad: function (options) {
    var that = this;
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/operationLogAction.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        currentPage: that.data.index + 1,
        typeName: that.data.contentName
      },
      success: function (res) {
        if (res.data.status == "success") {
          that.setData({
            szzstArr: res.data.data.pageList,
            page: res.data.data.pageTotalPageList,
            totalPage: res.data.data.totalPage
          })
        }
      }, fail: function (res) {
        wx.hideLoading();
        wx.showToast({
          title: '网络错误！',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    });
  },
  

  //转变查询来源  用户 还是 操作内容
  bindchangeSearch: function (e) {
    if (e.detail.value=="1"){
      this.setData({
        searchIndex: e.detail.value,
        searchShow: false,
        contentShow: true,
        userInputShow: false,
        userName:'',
        contentName:'',
        index:0,
        searchContentIndex:0
      })
    } else if (e.detail.value=="0"){
      this.setData({
        searchIndex: e.detail.value,
        searchShow: true,
        contentShow: false,
        userInputShow: true,
        userName: '',
        contentName: '',
        index:0,
        searchContentIndex:0
      })
    }
    var that = this;
    that.onLoad();
  },
  //点击操作内容下拉框
  bindchangeSearchContent: function (e) {
    let that = this;
    this.setData({
      searchContentIndex: e.detail.value,
      contentName: that.data.searchContent[e.detail.value],
      index: 0
    })
    that.onLoad();
  },
  //用户name的input函数
  userInput: function (e) {
    this.setData({
      userName: e.detail.value
    })
  },
  //查询
  searchClick: function (e) {
    var that = this;
    that.setData({
      index: 0
    })
    that.onLoading();
  },

  //点击页码
  bindchangePage: function (e) {
    let indexx = e.detail.value;
    this.setData({
      index: e.detail.value
    });
    var that = this;
    that.onLoading();
  },
  //公共方法，刷新数据
  onLoading: function (e) {
    let that = this;
    wx.request({
      url: 'https://wxapp.shuhai.cc/hh/operationLogAction.action',
      method: 'post',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        currentPage: that.data.index - 1 + 2,
        name: that.data.userName,
        typeName: that.data.contentName
      },
      success: function (res) {
        if (res.data.status == "success") {
          that.setData({
            szzstArr: res.data.data.pageList,
            page: res.data.data.pageTotalPageList,
            totalPage: res.data.data.totalPage
          })
        }
      }, fail: function (res) {
        wx.hideLoading();
        wx.showToast({
          title: '网络错误！',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    });
  },
  //上一页
  goPreviousPage: function (e) {
    var that = this;
    let index__ = this.data.index - 1;
    if (index__ <= 0) {
      index__ = 0;
    }
    this.setData({
      index: index__
    });
    that.onLoading();
  },
  //下一页
  goNextPage: function (e) {
    var that = this;
    let index__ = this.data.index - 1 + 2;
    if (index__ >= this.data.totalPage - 1) {
      index__ = this.data.totalPage - 1;
    }
    this.setData({
      index: index__
    });
    that.onLoading();
  }
})